Fix single item enum match type exhaustion#16966
Conversation
This comment has been minimized.
This comment has been minimized.
5cc30c9 to
60f6c4a
Compare
| reveal_type(m3) # N: Revealed type is "Tuple[Union[builtins.int, builtins.str]]" | ||
| [builtins fixtures/tuple.pyi] | ||
|
|
||
| [case testMatchEnumMultipleChoices] |
There was a problem hiding this comment.
This case is not strictly needed for this change. It just demonstrates how this should work normally. But I would think this is already covered. What do you think?
This comment has been minimized.
This comment has been minimized.
60f6c4a to
14699cb
Compare
This comment has been minimized.
This comment has been minimized.
14699cb to
885a84e
Compare
| typ = coerce_to_literal(typ) | ||
| narrowed_type, rest_type = self.chk.conditional_types_with_intersection( | ||
| current_type, [get_type_range(typ)], o, default=current_type | ||
| current_type, [get_type_range(typ)], o, default=get_proper_type(typ) |
There was a problem hiding this comment.
The issue was that on mypy/checker.py on conditional_types function, which is called by this self.chk.conditional_types_with_intersection , the conditional_types returns from here the default value:
Line 7399 in 2037e4a
When on regular enum that has multiple choices the conditional_types returns here instead:
Line 7415 in 2037e4a
But the first one returns wrong default value, so I am changing the default value here to be what the get_proper_type returns instead.
This comment has been minimized.
This comment has been minimized.
hauntsaninja
left a comment
There was a problem hiding this comment.
Thanks, this looks good to me (just made a minor tweak to the tests)
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
Fixes #14109